﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CompanyManageModel;
using CompanyManageRepositoryIServices;
using CompanyManageRepositoryServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CompanyManageAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CompanyController : ControllerBase
    {
        readonly ICompanyServices _CompanyServices;

        
        public CompanyController(ICompanyServices CompanyServices)
        {
            _CompanyServices = CompanyServices;
        }



        [HttpPost()]
        public void Add(Company company)
        {
            //ICompanyServices CompanyServices = new CompanyServices();
            try
            {
                _CompanyServices.Add(company);
            }
            catch (Exception e)
            {

            }

        }

        [HttpGet()]
        public void Delete(int id)
        {
            //ICompanyServices CompanyServices = new CompanyServices();
            _CompanyServices.DeleteById(id);

        }

        [HttpPost()]
        public void Update(Company employee)
        {
            //ICompanyServices CompanyServices = new CompanyServices();
            _CompanyServices.Update(employee);

        }

        [HttpGet()]
        public Task<List<Company>> GetAll()
        {
            //ICompanyServices CompanyServices = new CompanyServices();
            return _CompanyServices.Query();

        }
    }
}